﻿
@model Schedule

<!DOCTYPE html>

<html>
<head>
    <title>Schedule</title>
</head>
<body>
    <div>
        @using (Html.BeginForm())
        {
            @:Hours: @Html.DropDownList("hours", this.GetHours()) Minutes: @Html.DropDownList("minutes", this.GetMinutes())<br />
            <input type="submit" />
        }
    </div>
</body>
</html>

@functions {

    IEnumerable<SelectListItem> GetHours()
    {
        int hours = Model.Duration / 60;
        int maxHours = (5 * 60) / 60;

        for (int i = 0; i < maxHours; i++)
        {
            yield return new SelectListItem()
            {
                Text = i.ToString(),
                Value = i.ToString(),
                Selected = (hours == i)
            };
        }
    }

    IEnumerable<SelectListItem> GetMinutes()
    {
        int minutes = ((Model.Duration % 60) / 5) * 5;

        for (int i = 0; i < 60; i = i + 5)
        {
            yield return new SelectListItem()
            {
                Text = i.ToString(),
                Value = i.ToString(),
                Selected = (minutes == i)
            };
        }

    }
}
